/*
3364. 最小正和子数组
https://leetcode.cn/problems/minimum-positive-sum-subarray/submissions/584120444/
*/
class Solution {
public:
    int minimumSumSubarray(vector<int>& nums, int l, int r) {
        int n=nums.size();
        vector<int>qzh(n+1,0);
        qzh[0]=0;
        qzh[1]=nums[0];
        for(int i=2;i<=n;++i){
            qzh[i]=qzh[i-1]+nums[i-1];
        }
        bool flag=false;int minnum=9999999;
       // for(int t=0;t<=n;++t) cout<<qzh[t]<<" ";
        cout<<endl;
        for(;l<=r;++l){
            for(int t=1;t<=n-l+1;++t){
                if(!flag&&qzh[t+l-1]-qzh[t-1]>0) flag=true;   
                if(qzh[t+l-1]-qzh[t-1]>0)
                minnum=min(minnum,qzh[t+l-1]-qzh[t-1]);
                //cout<<qzh[t+l-1]<<" "<<qzh[t-1]<<" "<<endl;
        }
    }


        if(flag)
        return minnum;
        return -1;
    }
};